# Loading required package
library(stargazer)
# Loading the data
load("experiment_data.RData")

#############
# TABLE E.1 #
#############
# Gender
round(prop.table(table(experiment.data$GenderIdentity)),3)

# Race - create categories of white, black, hispanic/latino, asian, multiple races, other
round(length(which(experiment.data$Race %in% c("White")))/1250,3)
round(length(which(experiment.data$Race %in% c("Black or African American")))/1250,3)
round(length(which(experiment.data$Race %in% c("Hispanic or Latino","White,Hispanic or Latino")))/1250,3)
round(length(which(experiment.data$Race %in% c("Asian","Native Hawaiian or Pacific Islander")))/1250,3)
round(length(which(experiment.data$Race %in% c("American Indian or Alaska Native")))/1250,3)
round(length(which(experiment.data$Race %in% c("Black or African American,American Indian or Alaska Native","Black or African American,Hispanic or Latino",
                                                      "Black or African American,Hispanic or Latino,American Indian or Alaska Native","Hispanic or Latino,Asian",
                                                      "White,American Indian or Alaska Native","White,Asian","White,Asian,American Indian or Alaska Native,Native Hawaiian or Pacific Islander",
                                                      "White,Asian,Native Hawaiian or Pacific Islander","White,Black or African American","White,Black or African American,American Indian or Alaska Native",
                                                      "White,Black or African American,Asian,American Indian or Alaska Native","White,Black or African American,Hispanic or Latino",
                                                      "White,Hispanic or Latino,American Indian or Alaska Native","White,Hispanic or Latino,Asian","White,Other")))/1250,3)
round(length(which(experiment.data$Race %in% c("Other")))/1250,3)

# Partisanship, coding leaners as partisans
round(prop.table(table(experiment.data$democrat)),3)
round(prop.table(table(experiment.data$republican)),3)
round(prop.table(table(experiment.data$independent)),3)

# Education
round(prop.table(table(experiment.data$Education)),3)

# Income
round(prop.table(table(experiment.data$Income)),3)

# Ideology
round(prop.table(table(experiment.data$Ideology)),3)

#############
# TABLE E.2 #
#############
# Subsetting data to only respondents who took position
obstruction.experiment.position.only <- experiment.data[which(experiment.data$ObstructionSupport %in% c("Strongly support","Somewhat support","Strongly oppose","Somewhat oppose")),]

# Copartisans
# Mean level of support, any obstruction treatment
round(mean(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 
                                                                                 & obstruction.experiment.position.only$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
copartisan.severe.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                     obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "severe")])
round(copartisan.severe.position$estimate[2]-copartisan.severe.position$estimate[1],3)*100
copartisan.severe.position$p.value
# Test of difference of control and moderate means
copartisan.moderate.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                       obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "moderate")])
round(copartisan.moderate.position$estimate[2]-copartisan.moderate.position$estimate[1],3)*100
copartisan.moderate.position$p.value
# Test of difference of control and weak means
copartisan.weak.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                   obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$copartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "weak")])
round(copartisan.weak.position$estimate[2]-copartisan.weak.position$estimate[1],3)*100
copartisan.weak.position$p.value

# Independents
# Mean level of support, any obstruction treatment
round(mean(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 
                                                                                 & obstruction.experiment.position.only$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
independent.severe.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                      obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "severe")])
round(independent.severe.position$estimate[2]-independent.severe.position$estimate[1],3)*100
independent.severe.position$p.value
# Test of difference of control and moderate means
independent.moderate.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                        obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "moderate")])
round(independent.moderate.position$estimate[2]-independent.moderate.position$estimate[1],3)*100
independent.moderate.position$p.value
# Test of difference of control and weak means
independent.weak.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                    obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$independent.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "weak")])
round(independent.weak.position$estimate[2]-independent.weak.position$estimate[1],3)*100
independent.weak.position$p.value

# Outpartisans
# Mean level of support, any obstruction treatment
round(mean(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 
                                                                                 & obstruction.experiment.position.only$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
outpartisan.severe.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                      obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "severe")])
round(outpartisan.severe.position$estimate[2]-outpartisan.severe.position$estimate[1],3)*100
outpartisan.severe.position$p.value
# Test of difference of control and moderate means
outpartisan.moderate.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                        obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "moderate")])
round(outpartisan.moderate.position$estimate[2]-outpartisan.moderate.position$estimate[1],3)*100
outpartisan.moderate.position$p.value
# Test of difference of control and weak means
outpartisan.weak.position <- t.test(obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "control")],
                                    obstruction.experiment.position.only$obstruction.binary.support[which(obstruction.experiment.position.only$outpartisan.president == 1 & obstruction.experiment.position.only$obstruction.treatment.factor == "weak")])
round(outpartisan.weak.position$estimate[2]-outpartisan.weak.position$estimate[1],3)*100
outpartisan.weak.position$p.value

#############
# TABLE E.3 #
#############
# Copartisans (leaners as independents)
# Mean level of support, any obstruction treatment
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 
                                                                   & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
copartisan.severe.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                    experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
round(copartisan.severe.no.lean$estimate[2]-copartisan.severe.no.lean$estimate[1],3)*100
copartisan.severe.no.lean$p.value
# Test of difference of control and moderate means
copartisan.moderate.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                      experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
round(copartisan.moderate.no.lean$estimate[2]-copartisan.moderate.no.lean$estimate[1],3)*100
copartisan.moderate.no.lean$p.value
# Test of difference of control and weak means
copartisan.weak.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                  experiment.data$obstruction.binary.support[which(experiment.data$no.lean.copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
round(copartisan.weak.no.lean$estimate[2]-copartisan.weak.no.lean$estimate[1],3)*100
copartisan.weak.no.lean$p.value

# Independents
# All obstruction
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 
                                                                   & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
independent.severe.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                     experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
round(independent.severe.no.lean$estimate[2]-independent.severe.no.lean$estimate[1],3)*100
independent.severe.no.lean$p.value
# Test of difference of control and moderate means
independent.moderate.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                       experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
round(independent.moderate.no.lean$estimate[2]-independent.moderate.no.lean$estimate[1],3)*100
independent.moderate.no.lean$p.value
# Test of difference of control and weak means
independent.weak.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                   experiment.data$obstruction.binary.support[which(experiment.data$no.lean.independent.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
round(independent.weak.no.lean$estimate[2]-independent.weak.no.lean$estimate[1],3)*100
independent.weak.no.lean$p.value

# Outpartisans
# All obstruction
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 
                                                                   & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","severe"))]),3)*100

# Test of difference of control and severe means
outpartisan.severe.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                     experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
round(outpartisan.severe.no.lean$estimate[2]-outpartisan.severe.no.lean$estimate[1],3)*100
outpartisan.severe.no.lean$p.value
# Test of difference of control and moderate means
outpartisan.moderate.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                       experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
round(outpartisan.moderate.no.lean$estimate[2]-outpartisan.moderate.no.lean$estimate[1],3)*100
outpartisan.moderate.no.lean$p.value
# Test of difference of control and weak means
outpartisan.weak.no.lean <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                   experiment.data$obstruction.binary.support[which(experiment.data$no.lean.outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
round(outpartisan.weak.no.lean$estimate[2]-outpartisan.weak.no.lean$estimate[1],3)*100
outpartisan.weak.no.lean$p.value

#############
# TABLE E.4 #
#############
experiment.regression <- lm(obstruction.binary.support ~ copartisan.president + outpartisan.president + obstruction.treatment.factor + copartisan.president*obstruction.treatment.factor + 
                              outpartisan.president*obstruction.treatment.factor + man + college_degree + income_over_75000 + white + knowledge4, data=experiment.data)
summary(experiment.regression)

stargazer(experiment.regression, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Outpartisan of President","Moderate Obstruction",
                               "Severe Obstruction","Weak Obstruction","Man","College Degree","Income Over \\$75,000","White","Knowledge of SC (4 questions)",
                               "Copartisan of President $\\times$ Moderate Obstructionl",
                               "Copartisan of President $\\times$ Severe Obstruction",
                               "Copartisan of President $\\times$ Weak Obstruction",
                               "Outpartisan of President $\\times$ Moderate Obstructionl",
                               "Outpartisan of President $\\times$ Severe Obstruction",
                               "Outpartisan of President $\\times$ Weak Obstruction",
                               "Constant"),
          dep.var.labels = "DV: Support for Senate's Treatment of Nominee",
          dep.var.caption = "",
          title="Experimental Results: OLS Regression",
          label = "experiment-regression-table",
          keep.stat =  c("n","rsq","f"))
